﻿/// <reference name="MicrosoftAjax.js" />

//Fixed some bugs in Microsoft Ajax Library. js.

//修复了不能继承toString等方法的问题
//不修改源代码的方式是不正确的: 直接在父类的构造函数中定义, 
//虽然子类可使用父类的toString, 但子类没法Override toString()方法
//demo: 
/*
    Demo.Parent = function() {
        this.toString = function() {
            //DoSomething...
        }
    }
*/

//正确的方法如下:
Type.prototype.resolveInheritance = function Type$resolveInheritance() {
    if (arguments.length !== 0) throw Error.parameterCount();

    if (this.__basePrototypePending) {
        var baseType = this.__baseType;

        baseType.resolveInheritance();

        for (var memberName in baseType.prototype) {
            var memberValue = baseType.prototype[memberName];
            if (!this.prototype[memberName]) {
                this.prototype[memberName] = memberValue;
            }
        }
        /// #region additional code
        var couldNotForeachMembers = ["toString", "toLocalString", "valueOf",
            "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable"];
        
        for(var i = 0; i < couldNotForeachMembers.length; i++) {
            var couldNotForeachMemberName = couldNotForeachMembers[i];
            if(this.prototype[couldNotForeachMemberName] != Object.prototype[couldNotForeachMemberName])
                continue;
            
            var couldNotForeachMemberValue = baseType.prototype[couldNotForeachMemberName];
            if(memberValue != Object.prototype[couldNotForeachMemberName])
                this.prototype[couldNotForeachMemberName] = couldNotForeachMemberValue;
        }
        /// #endregion
        delete this.__basePrototypePending;
    }
}